export default {
  // 为当前模块开启命名空间
  namespaced: true,

  // 模块的 state 数据
  state: () => ({

    token: uni.getStorageSync('token') || '',
    // 用户的基本信息
    songsList: JSON.parse(uni.getStorageSync('songsList') || '[]'),
    // 推荐歌单详情列表索引
    // 修复第一个索引无法播放的bug把0改为null
    indexList: uni.getStorageSync('indexList') || null,
    // buttomControlList
    ControlList: JSON.parse(uni.getStorageSync('ControlList') || '[]'),
    itemMusicList: JSON.parse(uni.getStorageSync('itemMusicLists') || '{}')
  }),

  // 模块的 mutations 方法
  mutations: {
    // 上一首歌
    tapSub(state) {
      if (state.indexList === 0) {
        state.indexList = state.songsList.length
      }
      state.indexList -= 1

    },
    // 下一首
    tapAdd(state) {
      state.indexList += 1
      if (state.indexList === state.songsList.length) {
        state.indexList = 0
      }
    },
    // 底部控制的列表
    getbuttomControlList(state, list) {
      state.ControlList = list
      this.commit('musicDetailList/savebuttomControlListStorage')
    },
    getAllMusicList(state, songsList) {
      state.songsList = songsList
      this.commit('musicDetailList/saveAllMusicListStorage')
    },
    getItemMusicList(state, MusicList) {
      state.itemMusicList = MusicList
      this.commit('musicDetailList/saveItemMusicListStorage')
    },
    // 将 ControlList 持久化存储到本地
    savebuttomControlListStorage(state) {
      uni.setStorageSync('ControlList', JSON.stringify(state.ControlList))
    },
    // 将 itemMusicList 持久化存储到本地
    saveItemMusicListStorage(state) {
      uni.setStorageSync('itemMusicList', JSON.stringify(state.itemMusicList))
    },
    // 将songsList持久化存储到本地
    saveAllMusicListStorage(state) {
      uni.setStorageSync('songsList', JSON.stringify(state.songsList))
    },
    // 将indexList持久化存储到本地
    saveIndexListStorage(state) {
      uni.setStorageSync('indexList', state.indexList)
    },
    // 获取详情列表的索引
    tapMusicList(state, index) {
      state.indexList = index
      this.commit('musicDetailList/saveIndexListStorage')
    }
  },
  // 模块的 getters 属性
  getters: {

  },
}
